﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using com.gexin.rp.sdk.dto;
using com.igetui.api.openservice.igetui.template.notify;
using com.igetui.api.openservice.payload;

namespace com.igetui.api.openservice.igetui.template
{
	// Token: 0x02000045 RID: 69
	public class AbstractTemplate : ITemplate
	{
		// Token: 0x1700023C RID: 572
		// (get) Token: 0x0600052D RID: 1325 RVA: 0x0000C2C9 File Offset: 0x0000A4C9
		// (set) Token: 0x0600052E RID: 1326 RVA: 0x0000C2D1 File Offset: 0x0000A4D1
		public string AppId
		{
			get
			{
				return this.appId;
			}
			set
			{
				this.appId = value;
			}
		}

		// Token: 0x1700023D RID: 573
		// (get) Token: 0x0600052F RID: 1327 RVA: 0x0000C2DA File Offset: 0x0000A4DA
		// (set) Token: 0x06000530 RID: 1328 RVA: 0x0000C2E2 File Offset: 0x0000A4E2
		public string AppKey
		{
			get
			{
				return this.appKey;
			}
			set
			{
				this.appKey = value;
			}
		}

		// Token: 0x06000531 RID: 1329 RVA: 0x0000C2EC File Offset: 0x0000A4EC
		public Transparent getTransparent()
		{
			return Transparent.CreateBuilder().SetId("").SetTemplateId(this.getTemplateId()).SetMessageId("").SetTaskId("").SetAction("pushmessage").AddRangeActionChain(this.getActionChain()).SetPushInfo(this.getPushInfo()).SetAppId(this.AppId).SetAppKey(this.AppKey).AddCondition(this.getDurCondition()).Build();
		}

		// Token: 0x06000532 RID: 1330 RVA: 0x0000C36D File Offset: 0x0000A56D
		private string getDurCondition()
		{
			if (this.duration == null || this.duration.Equals(""))
			{
				return "";
			}
			return "duration=" + this.duration;
		}

		// Token: 0x06000533 RID: 1331 RVA: 0x0000C39F File Offset: 0x0000A59F
		public virtual string getTransmissionContent()
		{
			return "";
		}

		// Token: 0x06000534 RID: 1332 RVA: 0x0000C39F File Offset: 0x0000A59F
		public virtual string getPushType()
		{
			return "";
		}

		// Token: 0x06000535 RID: 1333 RVA: 0x0000C3A6 File Offset: 0x0000A5A6
		protected virtual List<ActionChain> getActionChain()
		{
			return null;
		}

		// Token: 0x06000536 RID: 1334 RVA: 0x0000C3A9 File Offset: 0x0000A5A9
		public PushInfo getPushInfo()
		{
			return this.pushInfo.Build();
		}

		// Token: 0x06000537 RID: 1335 RVA: 0x0000C3B8 File Offset: 0x0000A5B8
		public void setAPNInfo(Payload apn)
		{
			if (apn == null)
			{
				return;
			}
			string payload = apn.getPayload();
			if (payload == null || payload.Equals(""))
			{
				return;
			}
			int num = Encoding.UTF8.GetBytes(payload).Length;
			if (num > 2048)
			{
				throw new Exception(string.Concat(new object[]
				{
					"APN payload size overlength (",
					num,
					">",
					2048,
					")"
				}));
			}
			this.pushInfo.SetApnJson(payload).SetInvalidAPN(false);
		}

		// Token: 0x06000538 RID: 1336 RVA: 0x0000C44C File Offset: 0x0000A64C
		public void setPushInfo(string actionLocKey, int badge, string message, string sound, string payload, string locKey, string locArgs, string launchImage)
		{
			this.setPushInfo(actionLocKey, badge, message, sound, payload, locKey, locArgs, launchImage, 0);
		}

		// Token: 0x06000539 RID: 1337 RVA: 0x0000C470 File Offset: 0x0000A670
		public void setPushInfo(string actionLocKey, int badge, string message, string sound, string payload, string locKey, string locArgs, string launchImage, int contentAvailable)
		{
			APNPayload apnpayload = new APNPayload();
			DictionaryAlertMsg dictionaryAlertMsg = new DictionaryAlertMsg();
			dictionaryAlertMsg.ActionLocKey = actionLocKey;
			dictionaryAlertMsg.Body = message;
			dictionaryAlertMsg.LocKey = locKey;
			dictionaryAlertMsg.addLocArg(locArgs);
			dictionaryAlertMsg.LaunchImage = launchImage;
			apnpayload.AlertMsg = dictionaryAlertMsg;
			apnpayload.Badge = badge;
			apnpayload.Sound = sound;
			if (payload != null && payload.Length > 0)
			{
				apnpayload.addCustomMsg("payload", payload);
			}
			apnpayload.ContentAvailable = contentAvailable;
			this.setAPNInfo(apnpayload);
		}

		// Token: 0x0600053A RID: 1338 RVA: 0x0000C4F0 File Offset: 0x0000A6F0
		public void setDuration(string begin, string end)
		{
			long num = (Convert.ToDateTime(begin).Ticks - 621356256000000000L) / 10000L;
			long num2 = (Convert.ToDateTime(end).Ticks - 621356256000000000L) / 10000L;
			if (num <= 0L || num2 <= 0L)
			{
				throw new Exception("DateFormat: yyyy-MM-dd hh:mm:ss");
			}
			if (num > num2)
			{
				throw new Exception("startTime should be smaller than endTime");
			}
			this.duration = num + "-" + num2;
		}

		// Token: 0x0600053B RID: 1339 RVA: 0x0000C580 File Offset: 0x0000A780
		public void set3rdNotifyInfo(Notify notify)
		{
			if (notify.Title == null || notify.Content == null)
			{
				throw new Exception("notify title or content cannot be null");
			}
			NotifyInfo.Builder builder = NotifyInfo.CreateBuilder().SetTitle(notify.Title).SetContent(notify.Content);
			if (this.typeNotNull(notify.Type))
			{
				builder.SetType(notify.Type);
				if (notify.Payload != null && notify.Payload.Length > 0)
				{
					builder.SetPayload(notify.Payload);
				}
				if (notify.Intent != null && notify.Intent.Length > 0)
				{
					if (notify.Intent.Length > GtConfig.getTransIntentLength())
					{
						throw new Exception("intent size overlimit " + GtConfig.getTransIntentLength());
					}
					if (!this.reg.IsMatch(notify.Intent))
					{
						throw new Exception("intent format error,should start with \"intent:#Intent;\",end with \";end\" ");
					}
					builder.SetIntent(notify.Intent);
				}
				if (notify.Url != null && notify.Url.Length > 0)
				{
					builder.SetUrl(notify.Url);
				}
			}
			this.pushInfo.SetNotifyInfo(builder.Build()).SetValidNotify(true);
		}

		// Token: 0x0600053C RID: 1340 RVA: 0x0000C6B0 File Offset: 0x0000A8B0
		private bool typeNotNull(NotifyInfo.Types.Type type)
		{
			bool result = false;
			foreach (object obj in Enum.GetValues(typeof(NotifyInfo.Types.Type)))
			{
				if (((NotifyInfo.Types.Type)obj).Equals(type))
				{
					result = true;
				}
			}
			return result;
		}

		// Token: 0x0600053D RID: 1341 RVA: 0x0000C728 File Offset: 0x0000A928
		protected virtual int getTemplateId()
		{
			return -1;
		}

		// Token: 0x040002F0 RID: 752
		private string appId;

		// Token: 0x040002F1 RID: 753
		private string appKey;

		// Token: 0x040002F2 RID: 754
		private PushInfo.Builder pushInfo = PushInfo.CreateBuilder().SetInvalidAPN(true).SetInvalidMPN(true);

		// Token: 0x040002F3 RID: 755
		private string duration;

		// Token: 0x040002F4 RID: 756
		private Regex reg = new Regex("^(intent:#Intent;).*(;end)$");
	}
}
